package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.os.service.ReferFoodServiceX;
import com.os.serviceimpl.ReferFoodServiceImpX;

import net.sf.json.JSONObject;

public class ShowFoodBytypecontrollerX extends HttpServlet {
	
	
	ReferFoodServiceX rs  = new ReferFoodServiceImpX();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		HttpSession session = req.getSession();
		String type = req.getParameter("ftype");
		PrintWriter pw   = resp.getWriter();
		String page = req.getParameter("pageNumber");
		int rows = Integer.parseInt(req.getParameter("pageSize"));
		if(page==null){
			page = "1";
		}
		int pages  = Integer.parseInt(page);
		List list = rs.showFoodByftype(type, pages, rows);
		session.setAttribute("lists", list);
		int coun = rs.contfoodbytype(type);
		JSONObject jo =new JSONObject();
		jo.put("list", list);
		jo.put("total", coun);
		pw.write(jo.toString());
		pw.flush();pw.close();
		
}
		
}
